// ----------------------- MODULES -----------------------
var fs = require('fs'),
	express = require('express'),
	nodeunit = require('nodeunit'),
	app = express.createServer(),
	io = require('socket.io').listen(app);

// ----------------------- CONFIGURATION -----------------------
var properties = require('./conf/properties');

properties.configureApplication(app, express);

// ----------------------- INITIALIZE -----------------------
var initialize = require('./conf/initialize');

initialize.start();

// ----------------------- SOCKET.IO CONTROLLERS -----------------------
var categorySioController = require('./services/controllers/categorySioController'),
	placeSioController = require('./services/controllers/placeSioController'),
	wikimapiaCategorySioController = require('./services/controllers/wikimapiaCategoriesSioController');

io.sockets.on('connection', function(client) {
    categorySioController.tryEvent(client);
    placeSioController.tryEvent(client);
    wikimapiaCategorySioController.tryEvent(client);
});

// ----------------------- API REST CALLERS -----------------------
var categoryRestCaller = require('./services/callers/categoryRestCaller'),
	placeRestCaller = require('./services/callers/placeRestCaller');

categoryRestCaller.setCallers(app);
placeRestCaller.setCallers(app);

// ----------------------- PAGE RENDERS -----------------------
var home = require('./renders/homePageRender');

home.setRenders(app);

// ----------------------- LAUNCH APP -----------------------
app.listen(properties.applicationPort);
console.log('TickMap Middleware escuchando en el puerto ' + properties.applicationPort + '!!!');